package com.ks.pc.controller.asyn;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ks.dto.BrandDto;
import com.ks.dto.ClassifyDto;
import com.ks.dto.ProductDto;
import com.ks.dto.ResultDto;
import com.ks.pc.service.SysUeditorService;

/**
 * 
 * @author htpeng 2016��11��16������2:46:49
 */
@Controller
@RequestMapping("/sys")
public class SysUeditorControllerAsyn {
	@Autowired
	private SysUeditorService sysUeditorService;

	@ResponseBody
	@RequestMapping(value = "/ueditor/queryType", method = RequestMethod.POST)
	public List<ClassifyDto> queryType() {
		// List<NavigateDto> navigateList=ueditorService.queryMenu();
		// List<ModuleDto> moduleList=ueditorService.queryModule();
		List<ClassifyDto> list = sysUeditorService.queryAllClassify();
		List<BrandDto> list_b = sysUeditorService.queryAllBrand();
		if (null != list) {
			for (ClassifyDto cd : list) {
				if (null != list_b) {
					for (BrandDto bd : list_b) {
						if (cd.getId() == bd.getClassifyId()) {
							cd.setBrandDto(bd);
						}
					}
				}

			}
		}

		// map.put("product", navigateList);
		// map.put("type",moduleList);
		return list;
	}

	@ResponseBody
	@RequestMapping(value = "/ueditor/updateProduct", method = RequestMethod.POST)
	public ResultDto<String> updateProduct() {
		ResultDto<String> result = new ResultDto<String>();
		// boolean rs = false;
		result.setMsg("");
		// rs=ueditorService.updateNews(newsDto);
		return result;
	}

	/**
	 * 
	 * @param productDto
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/saveOrUpdateProduct", method = RequestMethod.POST)
	public boolean saveOrUpdateProduct(Integer productId, String productName, Integer brandId, Double price,
			Double downpayment, Double monthlyPrice, String cpu, String ram, String rom, String screenSize,
			String resolution, String camera, String card, String network, String time, Integer sort, Integer hot,
			Integer release, String content, @RequestParam("imgs[]") List<String> imgs, String pri_img,
			String salesLink, String master, String bag, String gcard, String position, String recommend) {
		ProductDto productDto = new ProductDto();
		productDto.setId(productId);
		productDto.setName(productName);
		productDto.setBrandId(brandId);
		productDto.setPrice(price);
		productDto.setDownPayment(downpayment);
		productDto.setMonthlyPayment(monthlyPrice);
		productDto.setCpu(cpu);
		productDto.setRom(rom);
		productDto.setCard(card);
		productDto.setRam(ram);
		productDto.setScreenSize(screenSize);
		productDto.setResolution(resolution);
		productDto.setCamera(camera);
		productDto.setNetwork(network);
		productDto.setShowIndex(sort);
		productDto.setHot(hot);
		productDto.setHasPublic(release);
		productDto.setContent(content);
		productDto.setImgs(imgs);
		productDto.setImgId(pri_img);
		productDto.setCreateTime(time);
		productDto.setSalesLink(salesLink);
		productDto.setMaster(master);
		productDto.setBag(bag);
		productDto.setGcard(gcard);
		productDto.setPosition(position);
		productDto.setRecommend(recommend);

		if (null == productDto.getId() || "".equals(productDto.getId())) {

			Integer id = sysUeditorService.saveProduct(productDto);
			if (null != id) {
				return true;
			}
			return false;
		} else {
			boolean rs = sysUeditorService.updateProductById(productDto);
			return rs;
		}

	}

}
